package com.google.code.chaotic.server;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.datanucleus.store.appengine.query.JDOCursorHelper;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ServerResource;

import com.google.appengine.api.datastore.Cursor;
import com.google.code.chaotic.ConversionUtil;
import com.google.code.chaotic.FrontTierTestsResource;
import com.google.code.chaotic.dto.CommuterDto;
import com.google.code.chaotic.dto.CommutingServiceDto;
import com.google.code.chaotic.model.Commuter;
import com.google.code.chaotic.model.CommutingHabit;
import com.google.code.chaotic.model.CommutingService;
import com.google.code.chaotic.model.HabitInService;
import com.google.code.chaotic.server.PmFactory;

/**
 * Resource which has only one representation.
 * 
 */
public class FrontTierTestsResourceImpl extends ServerResource //
		implements FrontTierTestsResource {

	Logger logger = Logger.getLogger(//
			FrontTierTestsResourceImpl.class.getName());

	//

	@Put
	@Override
	public String addCommuter(CommuterDto dto) {
		logger.info("\"commutung service addition\" request received!");
		PersistenceManager pm = PmFactory.get().getPersistenceManager();
		try {
			Commuter entity = ConversionUtil.dtoToEntity(dto);
			List<CommutingHabit> habits = entity.getCommutingHabits();
			// for (CommutingHabit habit : habits)
			// habit.setCServiceId(habit.getServiceId());
			entity.setId(null);
			pm.makePersistent(entity);
			return entity.getId();

		} finally {
			pm.close();
		}
	}
}